package com.powerband.apiheartrate.manager

import android.os.Build
import java.time.LocalDateTime
import java.util.Calendar
import java.util.Date

class FBKManagerCmd {

    val serialNo = byteArrayOf(0x03)
    val stepFrequency = byteArrayOf(0x04)
    val bloodOxygen = byteArrayOf(0x05)
    val resetFactory = byteArrayOf(0x07)
    val batteryState = byteArrayOf(0x0a)
    val switchMode =  byteArrayOf(0x0d)
    val devieMode = byteArrayOf(0x0e)
    val bandTime = byteArrayOf(0x10)
    val keepAlive = byteArrayOf(0x11)
    val sportDetail = byteArrayOf(0x13)
    val forseSleepOut = byteArrayOf(0x18)
    fun maxThreshold(v:Byte, v1:Byte): ByteArray = byteArrayOf(0x01,v1,v)

    fun lightCmd(on: Boolean): ByteArray = byteArrayOf(0x40, if (on) 0x01 else 0x00)
    fun disturbData(s: Boolean,h1: Int, m1: Int, h2: Int, m2: Int): ByteArray {
        val sV = if (s) 1 else 0
        return  byteArrayOf(0x14, sV.toByte(), h1.toByte(), m1.toByte(), h2.toByte(), m2.toByte())
    }
    fun syncTime(): ByteArray {
        var y: Int
        var m: Int
        var d: Int
        var h: Int
        var min: Int
        var s: Int
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            var current = LocalDateTime.now()
            y = current.year - 1970
            m = current.monthValue
            d = current.dayOfMonth
            h = current.hour
            min = current.minute
            s = current.second
        } else {
           var current = Date()
            y = current.year - 1970
            m = current.month
            d = current.day
            h = current.hours
            min = current.minutes
            s = current.seconds
        }
        return byteArrayOf(0x02,y.toByte(),m.toByte(),d.toByte(),h.toByte(),min.toByte(),s.toByte())
    }
}